// sorter.cpp : Defines the entry point for the console application.
// Author: Kourtni Marshall
// Date:   9/11/2009
//
// Program that times how long it takes to sort random integers.
//

#include "stdafx.h"
#include "cstdlib"
#include "iostream"
#include "vector"
#include "ctime"

using namespace std;



int main( int argc, char* argv[] )
{
	cout << strtod(argv[1], NULL) << " numbers were passed to sorter." << endl;
	long long nums_2_sort = (long long)strtod(argv[1], NULL); long long i;
	nums_2_sort = (nums_2_sort < 0) ? 0 - nums_2_sort : nums_2_sort; //change sign if nums_2_sort < 0
	int ceiling = (nums_2_sort <= RAND_MAX) ? (int)nums_2_sort : RAND_MAX;
	srand((int)time(NULL));

	int start, end; double elapsed;
	//int pStart, pEnd; double pElapsed;
	start = clock();
	vector<int> v (ceiling, 0); //initialize each index with 0
	for(i = 0; i < nums_2_sort; ++i){++v[rand() % ceiling];} //bucket sort
	end = clock(); elapsed = (double)(end - start)/CLOCKS_PER_SEC;

	//uncomment the block below to print sorted output to screen
	/**
	bool first = true;
	pStart = clock();
	//Print sorted output
	for(i = 0; i < ceiling; ++i){
		while(v[i] != 0){
			if(first){cout << i; first = false;}
			else{cout << ", " << i;}
			--v[i];
		}
	}
	cout << endl;
	pEnd = clock(); pElapsed = (double)(pEnd - pStart)/CLOCKS_PER_SEC;
	*/
	printf ("It took %.4lf seconds to sort %.1d numbers.\n", elapsed, nums_2_sort); //print sort time
	//printf ("It took %.4lf seconds to print %.1d numbers.\n", pElapsed, nums_2_sort); //print display times
}

